Ave Cruce Salus Mea ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; program: Win3ds34 - *.3ds / *.asc files viewer + demonstration of several graphics effects + tiny based on Bezier curves and patches 3d objects editor + some manipulation on 3d mesh routines. compiler: flat assembler author: Maciej Guba aka macgub web: http://macgub.co.pl - if this site not works, search the web for keyword 'macgub'. email: macgub@macgub.co.pl This application don't uses any particular 3d graphic library. Written from scratch in pure assembler. Thanks to all, who was helping me to do it. Especially: Jan Pawel II, Tomasz Grysztar, Madis Kalme, Mikolaj Feliks, Lostcauz, Brian Paul, Reverend, Pablo Reda, MHajduk, Ica, James Foley, Andries van Dam, Steven Feiner, John Hughes, Richard Phillips, tthsqe, J. Burkardt, Morgan McGuire, Pierre Bezier, Przemyslaw Kiciak and many others... Program needs SSE4 extension, in full mode. When only SEE3 is present some functions are disabled. After run program shows dialog to open file. Choose file in 3ds or asc format. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; User interface buttons description. Many GUI buttons is based on cyclic switching between options ex. 'rotary', 'dr.model', 'bumps', 'texture'.. When last option is achived, after next pressing button - first option is switched. This buttons have /flag/ - short description of option currently switched for example. 'rotary' button have /flags/ - 'y', 'x', 'z', 'cust'. Witch means rotate around axis y, x, z and custom rotary using mouse. Some buttons have no /flag/, after pressing such button only one operation (block of operations) is (are) performed. Such buttons are for ex. 'zoom in', 'zoom out', 'ran. light'. Moreover some options are avialable parallel, after pressing button or hiting keyboard key. For example chosing render model may be performed through 'dr. model' menu button or space key. Some operations have no GUI button, only key, for now such operations are: X key - load texture, N key - load new 3d object, M key - join object 3d to current existing. All key only operations are OS dependent file loading operations. Below I try write some information about GUI buttons. Keys / GUI Buttons description (under left mouse button click): SPACE key / 'dr. model' button - switching beetwen displaying models: flat, smooth shading, spherical environment, texture, bump, smooth + texture, two texture and bump + texture mapping pararell, edges only (smooth shaded, textured lines), flat with float single precision Z coordinate, point light with shadow light position dependent, real Phongs shading with float normal vector interpolation... Description of actual displaying model on bar located at top of app window. TAB / 'ran. light' button - generate three unlinear directional lights (Phongs illumination). F1 / 'mot. blur' button - motion blur on/off. F2 / 'cur object' - cyclic switching between objects (from file and predefined: heart (Sanctissimi Cordis Christi) and tetrahedron). F3/F4 and +/- keys / 'zoom in/out' buttons - no comment. F5 / 'tex. mapp.' button - choose bumps also texture mapping planar or spherical (planar according to axis X, Y, Z). f F6 / 'bumps' - switching between random bumps and texture dependent. F7 / 'texture' - select texture: red white stripes, xored face also blank (witch can by used in smoothing objects edges). App also allows load texture from external file (X key). F8 / 'save obj.' - save 3d currently shown object to file "object.asc" and "object.3ds" in current folder. F9 / 'Culling' - backface culling on/off. F11 / 'run/stop' button - main rotary on/off. F12 / 'rotary' - main rotary cyclic switching - around axis X, Y, Z and custom - use mouse and hold it's left button. D / 'do displ.' - do displacement mapping texture dependent. T / 'do triang.' - triangulize objects faces; it's mean divide each face to four smaller faces. Posibility to switch on teslation from separate area, use for this operation button 'Tes Wh/Tar' set flag of this button to 'tesA' -> area teslation. Setting flag of 'Tes Wh/Tar' button to 'Whol' means whole object teslation after pressing button described now ('do triang.'). Setting 't&d wh|pos' button flag to 'posi' means teslate only positiv (+) z coordinates vertices based faces. Flag 'whol' - teslate both positiv/negative z coordinates vertices based faces... To apply correct iteration teslation of only fragment of object, removing all cracks (see 'Rm cracks' button descriptiton) is obligatory, all cracks must be removed. U / 'rand. shd.' button - random point (spot) light position and obliquity of plane on wihch shadow falls. Visable in 'Shadow + spot light' dispalying/rendering model. V / 'edit mesh.' button - edit option, posibility to edit according to vertex, single face or edge. Use left mouse button and yellow handlers. W / 'set t. area' button - set teslate area - default is whole screen (some margin is not used). C / 'set t. col' - set color that will by bypassed when displacement occured, options - black, white. F / 'dsp. factor' - set diplacement factor, determine displaced bumps that make displacement higher or lower. B / 'bezier sr.' button - select Bezier patches, witch will be calculated and displayed. Now are prdefined three Bezier-patch objects - tea pot, tea cup and tea spoon. Posibility to edit such patch based object, (see 'b.der.edit' button description). A / 'set ap tol' button - set approximation tolerance when removing redundant vertices is launched. When vertices are enough /near/ they may be collapsed using 'Rm red ver' button. 'set ap tol' button sets haw much /near/ vertices to collapse should be. This button also determine spaces beetwen cloned/copied object (see 'make serie' button description). Also using this button user can change pipe diameter. Operation after hitting 'Long pipe' button. E / 'b.der.edit' button - draw Bezier derives, selected by B key, 'bezier sr.'button. Posiblity to edit Bezier patches by stopping animation (button 'run/stop') and move yellow bars with pressed left mouse button, when left button is released new position of bar and is accepted. Bezier patches are recalculated permanently. To achive previous geometry restart app. 't&d wh|pos' button - when displacement is performed (use butt 'do displ.' for diplac) determines wich part of object is affected.Flag -> 'posi' - only positive 'z' cooficient vertices are affected, if set on flag -> 'whol' all vertices are affected during displacement process. S / 'speed' button - toggle animation speed. Flags 'idle', 'full'. Some rendering models use only two threads, some four, a few diplaying models only one. 'Rm unu ver' button - remove unused vertices, other words remove this vertices that indexes are unused in triangles list. This option make vwrtices list shorter. P / 'Long pipe ' button - make long multi segment pipe based on Bspline or Bezier curve. If flag apropiate to this button is equal 'edit' -> editing pipe mode is switched - hold left mouse button on yellow bar - moving node, hold right mouse button and move mouset - rotate pipe project. By pressing once again 'Long pipe ' button -> set flag 'calc' - calculate and render pipe, diameter according to flag of 'set ap tol' . After next pressing 'Long pipe' butt base object is currenty displayed. 'culling' button switch backface culling default set 'off'. 'Lp segs cn' menu button - determine long pipe segmen ts count. 'Lp Bez/Bsp' button - determine type of curve that is base to making long pipe object. Flag options 'Bezr' - Bezier, flag 'Bspl' - Bspline type. 'Lp quality' - determine long pipe object quality (triangles count per segment. H / 'NextM edit' menu button - Draw /Next edit area/ that allow basic edition on /Next/ 3d object - (joined to earliest loaded mesh (use key 'M'). Draws bar I called /Next edit area/ below menu buttons and info area. If flag appropiate to this button is set on 'Nx. o': blue bar on this /Next edit area/ determines 'X','Y' position, violet bar determines 'Z' position, yellow bar determies scale of loaded freshly new part of mesh, red bar position - allow rotate around center point this part of 3d object, green bar allow unregular scale, only along 'X' and 'Y' axis. White bars - set bend of object Bezier curve dependent (bend work only of selected chunk - see below). Moving bars (with mouse and its left button) perform change parameters described above. Only vertical position of violet and yellow bars can be changed. For now drawing and edition using this /Next edit area/ requires enough (about 950 pixels) vertical resolution to displaying correctly. If flag appropiate to this button is set on 'chun' it enables separate chunk edition posibility. Press 'Show chunk' button and set its flag to 'on' - app will display bar on every triangle, unique to chunk posessed this tri. Click with left mouse button on bar and choose current chunk you will edit. Colored bars on /Next edit area/ now describes chunk editing posibilities. 'Rm red ver' button - removing redundand vertices, according to aproximation tolerancy value (use 'set ap tol' button to set this value). Removing redundant,/enough near/ vertices option is processed only on verts placed in teslate area - set this area using 'set t.area' button. O / 'Draw norm.' button - when flag of this button is set on 'tri.' drawing faces (triangles), when on 'vert' drawing vertices dependent normal vectors. R / 'Z rdu care' button - when set 'on' - take care about 'Z' cooficient of vertex during remove redundand vertices operation, when flag appropiate to this button shows 'off' during collapse enough /near/ vertices process, care on only on 'X' and 'Y' position of vertex. 'Rm red ver' button - perform removing redundant vertices operation (merging vertices). 'Rm ins fac' button - try to remove inside faces - that are covered by other faces outside mesh. This operation reduces faces and vertices number. Removing operation is solved by multi time rotating and projecting on about 1000x1000 pix area (not displayed), works correct when projected front, triangles area is not smaller then 1 pixel. Curently operation uses 4 threads. Be patient - it take some time no matter how complex is 3d object. (But calculations on bigger objects, that contains many vertices and faces for sure will take bigger period of time). 'Ma Coll Ed' button - mark and count - number displayed on /info area/ collided edges. It means edges that intersect other triangles. Flags allowed for button 'off' and 'on'. This operation will be slow on very complex objects. Brute force n to n solving method. Process use 4 threads for now. 'Srch Chunk' button - search for seprate manifold chunks. Try find edge of triangles that are adjacent one to another. It mean form one of such triangle is possible "go" to other triangle across its edges (I promote to vertices) to other triangle from separate chunk. Chunks are counted, numer displayed on /info area/. 'Sm ins edg' button - smooth inside edges. It is simplification mesh option. After removing inside faces (which is also simplifi- cation option), inside edges of apropiate faces/triangles that are removed, are usually jagged. This option try to fix such situation. Some small margin is leaved. Option require correct senses of normal vectors. May be slow. 'Clip faces' - clip faces that are in triangulation (teslate) area such area can be set using 'set t. area' button. 'Invert chn' button - invert sense of normal vectors in one separate chunk. first the 'Srch Chunk' button should be set 'on', then pause animation using 'run/stop' button and switch 'Show chunk' button flag 'on'. Than move mouse cursot on unique triangle mark (bar with unique color, in center of each triangle, separate to each chunk) and click with left mouse button. Senses of all normal vectors in whole chunk that posesed triangle you click will be reversed. 'Crop front' button - crop front (of view area) faces, some small margin (a few degrees in each direction) is leaved. 'Del. chunk' button. - By pressing this button set its flag to 'Del.' - ability to delete separate chunk, first the 'Srch Chunk' button should be set "on", then pause animation using 'run/stop' button, move mouse cursot on unique triangle mark (bar with unique color, in center of triangle, separate to each chunk) and click with left mouse button. Selected chunk will be deleted. Object parameters verts/faces/edges/chunks will be recalculated after each delete operation; 'Ray shadows' button - calculate and display ray casted shadows of mesh. This option is done on 4 threads. To see shadows object must have proper geometry. Part of mesh cover other objects parts hidden to impact of light ray. Operation use three points light sources. Non realtime on complex objects. 'Tes TIV IE' button - teslate(triangulize) triangles with at last one inside vertex and at at last one edge that intersect. First 'Ma Coll Ed' - mark collided edges and 'Mark in vr' - mark inner vertices buttons flags must be set 'on'. 'Mark in vr' button - searching for inside vertices option. Vertices are counted. This value is displayed on /info area/ - below buttons menu area. Calculations may take some time - its done using many palarell projections. 'Rm TIV NIE' button - remove triangles with at last one inside vertex and wihout any intersected edge. First 'Ma Coll Ed' -> -> mark collided edges and 'Mark in vr' -> mark inside vertices buttons falgs must be set 'on'. 'Rm dead tr' button - some triangles have duplicated, or even tripled index of vertex - so it geometric representation is line, or point - remove such triangles to save memory space. 'Rm cracks' button - remove cracks. After teslation of chosen area of object (not whole} may take place such unneeded artifact: Along edge may occur an vertex thats only touch edge but is not possesed by this edge. Routine adjacent to this button cure this situation. Only vertces thats are in the middle of edge are computed, so operations may require repeating to patch all cracks. Removing all cracks is obligatory to perform correctly teslate/ /triangulation operation when not whole object is affected. See 'do triang.' button description. 'Tes Wh/Tar' button - set flag teslation mode (under 'do triang' button) if flag of this button is set to 'tesA' -> area teslation. Setting flag of 'Tes Wh/Tar' button to 'Whol' means whole object teslation after pressing button 'do triang.' button. 'Show chunk' - show manifold chunks bars, color is individual for each chunk. Chunks may be found by 'Srch Chunk' button. 'tex +', 'tex -' buttons - changes 'zoom' of texture mapping. Visual effect may be difrent in various rendering models - (clipped/tiled/..). 'fix norm V' button - fixing normal vectors option - Do random rotary and parallel projection two times with disabled and enabled backface culling. Triangles that was rendered first time and not second time have non correct sense of normal vector. (Render operation is performed only in iside memory area, non displayed on screen.) Pressing a few times this button make posible cure mismatched sense of normal vectors. Use this option when mismatched normals are inside separate chunk. If whole chunk has uncorrected nomal vectors - better use 'Invert chn' option and button. 'make serie' button - make copy of current object, and display this copy with increased current 'X' coord value - this value determines 'set ap tol' button flag/value. 'sort chunks' - sort triangles list according to detected manifold chunks. Also do chunks structure - describes min, max, middle vertices coordinates in chunk. I tried rearange vertices list - tried perform situation when every chunk has one continous part of this list. But now its to buggy. 'Submit obj' - this button allow submit changes after ex. separate chunks edition. 'Zero Next' button - allow seting /Next variables/ - showed as color bars on /Next edit area/ to its start position. 'Mirror ch.' - allow perform mirror X axis depend reflection of chosen chunk. First display chunks using 'Show chunk' button. Set flag of button I describe in this paragraph to 'on' and click mouse left button on bar visulise chunk you want to mirror. X key - load texture (raw format 512X512 pixels 24bit 0xRRGGBB). I tried bmp format, (uncompressed 24, 8, 4bit win and os2 versions) but it is very buggy. N key - load new mesh (old will be abandoned). M key - load new mesh and join it to the old; Posibility to edit position of fresh load mesh using 'NextM edit' button. See description of this button for details. ESC key - exit. Right mouse pressed button and move - setting position of texture, (works in all drawing models, but is visable only in texture displaying models). General note about implemented operations. - Some of it may run teribly slow aspecially on 'large' objects. Maybye some tests for low detail objects may prevent your speed disapointing. Note that even operations on small objects may be slow, bacause way of sloving problem. Its 32 bit app, so object above ~10 000 000 vertices/faces may be to big for 4GB RAM limit - some operations alloc temporaly many memory (because using mem greedy pivot lists). Many operation cannot be launched parallel in the same time (ex. editing - chunks - bezier patches - long pipes). "No work is ever complete, and this one is no exception." Pierre Bezier